package com.cskaoyan.controller.wx;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.wxsearch.RegisterBO;
import com.cskaoyan.service.WXAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


@RestController
@RequestMapping("wx")
public class WXAuthController {

    @Autowired
    WXAuthService wxAuthService;
String sms ;
    //获取验证码
    @PostMapping("/auth/regCaptcha")
    public BaseRespVo authRegCaptcha(@RequestBody Map map) {
        String mobile = (String) map.get("mobile");
        String s =wxAuthService.authRegCaptcha(mobile);
        sms =s;
        return BaseRespVo.ok();
    }


    @PostMapping("/auth/register")
    public BaseRespVo authRegister(@RequestBody RegisterBO registerBO) {
        if (sms.equals(registerBO.getCode())){
            wxAuthService.authRegister(registerBO);

            return BaseRespVo.ok();
        }else {

            return BaseRespVo.fail("验证码错误");
        }

    }

    @PostMapping("/auth/reset")
    public BaseRespVo authReset(@RequestBody Map map) {

        int code = wxAuthService.authReset(map);

        return BaseRespVo.ok();

    }

}